<?php
	//include("admin_check.inc.php");
	//include("config.inc.php");
	include("dbconnect.inc.php");
	if($_GET["ok"] == "1") $message="操作完成";
	if($_GET["do"] == "1") {
		$category_name = mysql_real_escape_string($_POST["category_name"]);
		$order_id =  $_POST["order_id"];
		$id = $_POST["id"];
		$message = "";
		if($category_name == "") {
			$message .= "栏目名不能为空<br />";
		}
		if(!is_numeric($order_id)) {
			$message .= "排序号必须为数字<br />";
		}
		if(!is_numeric($id)) {
			$message .= "id错误<br />";
		}
		if($message == "") {
			$sql = "update  category set category_name='{$category_name}' ,order_id={$order_id} where id={$id} ";
			if(mysql_query($sql)) {
				$message = "更新成功";
				header("Location:list.php?category={$id}&ok=1");
			}else {
				$message = "添加失败，DB错误";
			}
		}
	}
	if(is_numeric($_GET["id"])) {
		$id = $_GET["id"];
		$res = mysql_query("select * from category where id={$id}");
		$row = mysql_fetch_array($res);
		$category_name = $row["category_name"];
		$order_id = $row["order_id"];
		$id = $row["id"];
	}
	if(is_numeric($_GET["del"])) {
		$id = $_GET["del"];
		if(mysql_query("delete from category where id={$id}")) {
				$message = "删除完成";
				header("Location:".$_REQUEST["ref"]);
		}else {
				$message = "删除失败，DB错误";
		}
	}
?>
<?php include("header.inc.php"); ?>
<script language="javascript">
	function doDel(title,id,ref) {
		ref='<?php echo $_SERVER['HTTP_REFERER']; ?>';
		if(confirm('你确定要删除栏目\n-------------------------\n'+title+'\n-------------------------'))
			location.href='admin_editcategory.php?del='+id+'&ref='+ref;
	}
</script>
<table width="778" border="0" cellpadding="0" cellspacing="6" class="border">
  <tr> 
    <td valign="top" width="100%" class="listcontent" align="center"> 
          <b><?Php echo $message; ?></b>
      <table width="100%" border="0" cellpadding="6" cellspacing="0">
        <tr> 
          <td class="listTitle"> 
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td><strong>编辑栏目</strong></td><td align=right>&nbsp;</td>

                </tr>
            </table>
          </td>
        </tr>
        <tr> 
          <td valign="top" class="list"> 

			<form action="admin_editcategory.php?do=1" method="post">
				栏目标题：<input type="text" name="category_name" size="50" value="<?php echo $category_name; ?>" /><br />
				排序数字：<input type="text" name="order_id" size="10" value="<?php echo $order_id; ?>" /><br />
					<input type="hidden" name="id" value="<?php echo $id; ?>" />
				<input type="submit" value="更　　新" />&nbsp;&nbsp;
				<input type="button" value="删　　除"  onclick="doDel('<?php echo $category_name; ?>','<?php echo $id; ?>');" />
			</form>

          </td>
        </tr>
      </table>
    </td>

  
  </tr>
</table>
<?php include("footer.inc.php"); ?>